package com.wjh.controller;

import com.wjh.bean.Constants;
import com.wjh.bean.Result;
import com.wjh.common.UrlCommon;
import com.wjh.feign.MemberServiceFeign;
import com.wjh.pojo.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/6/13.
 * @Modified By:
 */
@Controller
@RequestMapping("/register")
public class RegisterController extends UrlCommon{

    @Autowired
    MemberServiceFeign memberServiceFeign;
    @GetMapping
    public String Register(){
        return REGISTER;
    }

    @PostMapping
    public String Register(UserEntity userEntity, HttpServletRequest request){
        Result regust = memberServiceFeign.regust(userEntity);
        if (regust.getCode()!= Constants.HTTP_RES_CODE_200) {
            request.setAttribute("error",regust.getMsg());
            return REGISTER;
        }
        return "redirect:"+LOGIN;
    }
}
